/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package UI;

import BL.BLFuncionario;
import BL.BLGastoAdicional;
import BL.BLOrden;
import BL.BLViaticoPorDia;
import BO.Funcionario;
import BO.OrdenDeViaticos;
import Utilitarios.ButtonColumn;
import Utilitarios.Utilitarios;
import Utilitarios.Verificador;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author David
 */
public class FrmOrdenDeViaticos extends javax.swing.JFrame {

   
    private int numOrden;
    java.util.Date fecha = new Date();
    private ArrayList jefes;
    private FrmDiaViatico VentanaDiaViatico;
    private FrmOtrosGastos VentanaOtrosGastos;
    private DefaultTableModel ModeloTablaViaticos;
    private DefaultTableModel ModeloOtrosGastos;
    private boolean bandera;
    public FrmOrdenDeViaticos(int numeroOrden) throws SQLException {
       this.setSize(new Dimension(1400, 500));
       initComponents();
        numOrden=0;
        bandera=false;
        numOrden=numeroOrden;
        this.lbNum.setText(String.valueOf(numOrden));
        this.lbFecha.setText(fecha.toString());
         jefes= new ArrayList();        
        jefes=BLFuncionario.obtenerJefes();
        this.llenarComboJefes();
        ModeloTablaViaticos= new DefaultTableModel(new Object[]{"Fecha","IdCanton","Hora Entrada","Hora Salida","Desayuno","Almuerzo","Cena","Hospedaje","Total Diario","Centro Costo","Consecutivo",""}, 0);
        TblViaticosDia.setModel(ModeloTablaViaticos);
         
        Action delete2 = new AbstractAction(){
            public void actionPerformed(ActionEvent e)
            {
                TblViaticosDia = (JTable)e.getSource();
                int modelRow = Integer.valueOf( e.getActionCommand() );
                ((DefaultTableModel)TblViaticosDia.getModel()).removeRow(modelRow);
            }
            };
 
        ButtonColumn buttonColumn1 = new ButtonColumn(TblViaticosDia, delete2, 11);
        buttonColumn1.setMnemonic(KeyEvent.VK_D);
        ModeloOtrosGastos= new DefaultTableModel(new Object[]{"Consecutivo","Monto","Centro de Costo","Descripcion",""}, 0);
        TblOtrosGastos.setModel(ModeloOtrosGastos);
  
        Action delete = new AbstractAction(){
            public void actionPerformed(ActionEvent e)
            {
                TblOtrosGastos = (JTable)e.getSource();
                int modelRow = Integer.valueOf( e.getActionCommand() );
                ((DefaultTableModel)TblOtrosGastos.getModel()).removeRow(modelRow);
            }
            };
 
        ButtonColumn buttonColumn = new ButtonColumn(TblOtrosGastos, delete, 4);
        buttonColumn.setMnemonic(KeyEvent.VK_D);
        txtCedula.setInputVerifier(new Verificador());
        txtBanco.setInputVerifier(new Verificador());
        txtNumAnticipo.setInputVerifier(new Verificador());
        txtObservaciones.setInputVerifier(new Verificador());
        TxtObjetivo.setInputVerifier(new Verificador());
        Calendar calendario = new GregorianCalendar();
        txtAño1.setText(""+calendario.get(Calendar.YEAR));
        txtMes.setText(""+calendario.get(Calendar.MONTH));
        txtDia.setText(""+calendario.get(Calendar.DAY_OF_MONTH));
    }
    
      public final void llenarComboJefes()
    {
     this.cmbAutoriza.removeAllItems();
       for (Object funcionario : jefes) {
           String nombre = ((Funcionario) funcionario).getNombre();
           int cedula = ((Funcionario) funcionario).getCedula();
           this.cmbAutoriza.addItem(nombre+"-"+cedula);
       }
     
    }
      
      private boolean guardarDatos()
      {
        int cedula= Integer.parseInt(this.txtCedula.getText());
        int numeroAnticpio= Integer.parseInt(this.txtNumAnticipo.getText());
        String banco= this.txtBanco.getText();
        double montoAnticipo= Double.parseDouble(this.txtMontoAnticipo.getText());
        String objetivo= this.TxtObjetivo.getText();
        String Observaciones= this.txtObservaciones.getText();
        String []separarJefe= this.cmbAutoriza.getSelectedItem().toString().split("-");
        int autoriza= Integer.parseInt(separarJefe[1]);
        String fechaReintegro=this.txtIDRecibo+"-"+this.txtMes+"-"+this.txtDia;
        
        
        
          
          return true;
      }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane3 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel4 = new javax.swing.JLabel();
        lbNum = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        lbFecha = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        LblTitulo = new javax.swing.JLabel();
        LblCedula = new javax.swing.JLabel();
        txtCedula = new javax.swing.JTextField();
        LblAnticipo = new javax.swing.JLabel();
        txtNumAnticipo = new javax.swing.JTextField();
        LblBanco = new javax.swing.JLabel();
        txtBanco = new javax.swing.JTextField();
        LblOtrosGastos = new javax.swing.JLabel();
        jScrollPane5 = new javax.swing.JScrollPane();
        TblViaticosDia = new javax.swing.JTable();
        BtnAgregarDesglose = new javax.swing.JButton();
        txtMontoAnticipo = new javax.swing.JTextField();
        LblMonto = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        TblOtrosGastos = new javax.swing.JTable();
        BtnAgregarOtroDetalle = new javax.swing.JButton();
        cmbAutoriza = new javax.swing.JComboBox();
        LblFechaReintegro = new javax.swing.JLabel();
        txtMes = new javax.swing.JTextField();
        txtDia = new javax.swing.JTextField();
        txtIDRecibo = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        LblDD = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        LblMM = new javax.swing.JLabel();
        LblYYYY = new javax.swing.JLabel();
        LblObservaciones = new javax.swing.JLabel();
        LblObjetivo = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        btnAgregar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        TxtObjetivo = new javax.swing.JTextField();
        BtnCalcularGastosDiarios = new javax.swing.JButton();
        LblAutoriza = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        LblResta = new javax.swing.JLabel();
        LblTotalHospedajeL = new javax.swing.JLabel();
        LblSubTotal1L = new javax.swing.JLabel();
        LblTotalOtrosL = new javax.swing.JLabel();
        LblTotal = new javax.swing.JLabel();
        LblTotalAlimen = new javax.swing.JLabel();
        LblTotalAlimentacion = new javax.swing.JLabel();
        LblTotalHospedaje = new javax.swing.JLabel();
        LblSubTotal1 = new javax.swing.JLabel();
        LblTotalOtros = new javax.swing.JLabel();
        LblTotalViaticos = new javax.swing.JLabel();
        LblResultado = new javax.swing.JLabel();
        LblFechaReintegro1 = new javax.swing.JLabel();
        txtAño1 = new javax.swing.JTextField();
        txtObservaciones = new javax.swing.JTextField();

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane3.setViewportView(jTable1);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBounds(new java.awt.Rectangle(0, 0, 0, 0));
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setMaximizedBounds(new java.awt.Rectangle(0, 0, 0, 0));
        setMaximumSize(new java.awt.Dimension(900, 700));
        setMinimumSize(new java.awt.Dimension(900, 700));
        setPreferredSize(new java.awt.Dimension(950, 650));
        setResizable(false);
        getContentPane().setLayout(null);

        jLabel4.setText("Numero de Orden: ");
        getContentPane().add(jLabel4);
        jLabel4.setBounds(690, 50, 92, 14);

        lbNum.setForeground(new java.awt.Color(255, 0, 0));
        lbNum.setText("00000");
        getContentPane().add(lbNum);
        lbNum.setBounds(790, 50, 30, 14);

        jLabel7.setText("Fecha:");
        getContentPane().add(jLabel7);
        jLabel7.setBounds(690, 70, 33, 14);

        lbFecha.setText("dd/mm/yy");
        getContentPane().add(lbFecha);
        lbFecha.setBounds(730, 70, 48, 14);

        jPanel1.setAutoscrolls(true);
        jPanel1.setMinimumSize(new java.awt.Dimension(900, 850));
        jPanel1.setName(""); // NOI18N
        jPanel1.setPreferredSize(new java.awt.Dimension(900, 300));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        LblTitulo.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        LblTitulo.setForeground(new java.awt.Color(102, 102, 102));
        LblTitulo.setText("Nueva Orden de Viaticos ");
        jPanel1.add(LblTitulo, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 10, -1, -1));

        LblCedula.setText("Cedula del funcionario: ");
        jPanel1.add(LblCedula, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 90, -1, -1));

        txtCedula.setNextFocusableComponent(txtBanco);
        txtCedula.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCedulaActionPerformed(evt);
            }
        });
        jPanel1.add(txtCedula, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 80, 160, 30));

        LblAnticipo.setText("Numero de anticipo:");
        jPanel1.add(LblAnticipo, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 130, -1, -1));
        jPanel1.add(txtNumAnticipo, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 120, 160, -1));

        LblBanco.setText("Banco:");
        jPanel1.add(LblBanco, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 90, -1, -1));

        txtBanco.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtBancoActionPerformed(evt);
            }
        });
        jPanel1.add(txtBanco, new org.netbeans.lib.awtextra.AbsoluteConstraints(480, 90, 150, -1));

        LblOtrosGastos.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        LblOtrosGastos.setText("Gastos de Transporte y Otros segun Facturas");
        jPanel1.add(LblOtrosGastos, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 340, -1, -1));

        TblViaticosDia.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane5.setViewportView(TblViaticosDia);

        jPanel1.add(jScrollPane5, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 190, 850, 130));

        BtnAgregarDesglose.setText("Agregar");
        BtnAgregarDesglose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnAgregarDesgloseActionPerformed(evt);
            }
        });
        jPanel1.add(BtnAgregarDesglose, new org.netbeans.lib.awtextra.AbsoluteConstraints(870, 220, -1, -1));

        txtMontoAnticipo.setText("0");
        jPanel1.add(txtMontoAnticipo, new org.netbeans.lib.awtextra.AbsoluteConstraints(480, 120, 290, -1));

        LblMonto.setText("Monto Anticipo:");
        jPanel1.add(LblMonto, new org.netbeans.lib.awtextra.AbsoluteConstraints(390, 120, -1, -1));

        TblOtrosGastos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane4.setViewportView(TblOtrosGastos);

        jPanel1.add(jScrollPane4, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 370, 560, 120));

        BtnAgregarOtroDetalle.setText("Agregar");
        BtnAgregarOtroDetalle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnAgregarOtroDetalleActionPerformed(evt);
            }
        });
        jPanel1.add(BtnAgregarOtroDetalle, new org.netbeans.lib.awtextra.AbsoluteConstraints(580, 370, -1, -1));

        cmbAutoriza.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbAutorizaActionPerformed(evt);
            }
        });
        jPanel1.add(cmbAutoriza, new org.netbeans.lib.awtextra.AbsoluteConstraints(530, 510, 180, -1));

        LblFechaReintegro.setText("Numero Recibo Reintegro");
        jPanel1.add(LblFechaReintegro, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 510, -1, -1));

        txtMes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtMesActionPerformed(evt);
            }
        });
        jPanel1.add(txtMes, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 510, 30, -1));
        jPanel1.add(txtDia, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 510, 30, -1));

        txtIDRecibo.setText("0");
        txtIDRecibo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtIDReciboActionPerformed(evt);
            }
        });
        jPanel1.add(txtIDRecibo, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 510, 60, -1));

        jLabel8.setText("/");
        jPanel1.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, 510, 20, 20));

        LblDD.setText("DD");
        jPanel1.add(LblDD, new org.netbeans.lib.awtextra.AbsoluteConstraints(320, 540, -1, -1));

        jLabel15.setText("/");
        jPanel1.add(jLabel15, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 510, 10, 20));

        LblMM.setText("MM");
        jPanel1.add(LblMM, new org.netbeans.lib.awtextra.AbsoluteConstraints(370, 540, -1, -1));

        LblYYYY.setText("YYYY");
        jPanel1.add(LblYYYY, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 530, -1, 30));

        LblObservaciones.setText("Observaciones:");
        jPanel1.add(LblObservaciones, new org.netbeans.lib.awtextra.AbsoluteConstraints(390, 160, -1, -1));

        LblObjetivo.setText("Objetivo:");
        jPanel1.add(LblObjetivo, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 160, -1, -1));

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/fod-logo.png"))); // NOI18N
        jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(380, -10, 70, -1));

        btnAgregar.setText("Agregar");
        btnAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarActionPerformed(evt);
            }
        });
        jPanel1.add(btnAgregar, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 590, 90, 30));

        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });
        jPanel1.add(btnCancelar, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 590, 90, 30));

        TxtObjetivo.setToolTipText("");
        jPanel1.add(TxtObjetivo, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 160, 160, -1));

        BtnCalcularGastosDiarios.setText("Calcular Gastos");
        BtnCalcularGastosDiarios.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnCalcularGastosDiariosActionPerformed(evt);
            }
        });
        jPanel1.add(BtnCalcularGastosDiarios, new org.netbeans.lib.awtextra.AbsoluteConstraints(790, 590, -1, -1));

        LblAutoriza.setText("Autoriza: ");
        jPanel1.add(LblAutoriza, new org.netbeans.lib.awtextra.AbsoluteConstraints(480, 510, -1, -1));

        jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        LblResta.setFont(new java.awt.Font("Segoe UI Light", 0, 12)); // NOI18N
        LblResta.setText("Anticipo - Total");
        jPanel2.add(LblResta, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 210, -1, -1));

        LblTotalHospedajeL.setFont(new java.awt.Font("Segoe UI Light", 0, 14)); // NOI18N
        LblTotalHospedajeL.setText("Total Hospedaje");
        jPanel2.add(LblTotalHospedajeL, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 60, -1, -1));

        LblSubTotal1L.setFont(new java.awt.Font("Segoe UI Light", 0, 14)); // NOI18N
        LblSubTotal1L.setText("SubTotal");
        jPanel2.add(LblSubTotal1L, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 100, -1, -1));

        LblTotalOtrosL.setFont(new java.awt.Font("Segoe UI Light", 0, 12)); // NOI18N
        LblTotalOtrosL.setText("Total Otros");
        jPanel2.add(LblTotalOtrosL, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 150, -1, -1));

        LblTotal.setFont(new java.awt.Font("Segoe UI Light", 0, 12)); // NOI18N
        LblTotal.setText("Total");
        jPanel2.add(LblTotal, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 180, -1, -1));

        LblTotalAlimen.setFont(new java.awt.Font("Segoe UI Light", 0, 14)); // NOI18N
        LblTotalAlimen.setText("Total Alimentación");
        jPanel2.add(LblTotalAlimen, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 20, -1, -1));

        LblTotalAlimentacion.setBackground(java.awt.SystemColor.activeCaption);
        LblTotalAlimentacion.setFont(new java.awt.Font("Segoe UI Light", 0, 14)); // NOI18N
        LblTotalAlimentacion.setText("####");
        jPanel2.add(LblTotalAlimentacion, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 20, 90, -1));

        LblTotalHospedaje.setBackground(java.awt.SystemColor.activeCaption);
        LblTotalHospedaje.setFont(new java.awt.Font("Segoe UI Light", 0, 14)); // NOI18N
        LblTotalHospedaje.setText("####");
        LblTotalHospedaje.setToolTipText("");
        jPanel2.add(LblTotalHospedaje, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 60, 70, -1));

        LblSubTotal1.setFont(new java.awt.Font("Segoe UI Light", 1, 18)); // NOI18N
        LblSubTotal1.setText("####");
        jPanel2.add(LblSubTotal1, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 100, 90, 20));

        LblTotalOtros.setFont(new java.awt.Font("Segoe UI Light", 0, 12)); // NOI18N
        LblTotalOtros.setText("####");
        jPanel2.add(LblTotalOtros, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 140, 80, 20));

        LblTotalViaticos.setFont(new java.awt.Font("Segoe UI Light", 1, 18)); // NOI18N
        LblTotalViaticos.setText("total");
        jPanel2.add(LblTotalViaticos, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 170, -1, -1));

        LblResultado.setFont(new java.awt.Font("Segoe UI Light", 0, 12)); // NOI18N
        LblResultado.setText("Resultado");
        jPanel2.add(LblResultado, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 210, -1, -1));

        jPanel1.add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(720, 330, 220, 250));

        LblFechaReintegro1.setText("Fecha Reintegro:");
        jPanel1.add(LblFechaReintegro1, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 510, -1, -1));

        txtAño1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtAño1ActionPerformed(evt);
            }
        });
        jPanel1.add(txtAño1, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 510, 60, -1));
        jPanel1.add(txtObservaciones, new org.netbeans.lib.awtextra.AbsoluteConstraints(480, 150, 290, 30));

        getContentPane().add(jPanel1);
        jPanel1.setBounds(0, 0, 950, 640);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtCedulaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCedulaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtCedulaActionPerformed

    private void txtBancoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtBancoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtBancoActionPerformed

    private void txtMesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtMesActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtMesActionPerformed

    private void cmbAutorizaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbAutorizaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cmbAutorizaActionPerformed


    private void btnAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarActionPerformed
        // TODO add your handling code here:
        // GuardarViaticoPrincipal
        if(bandera){
            int cedula= Integer.parseInt(this.txtCedula.getText());
            int numeroAnticpio= Integer.parseInt(this.txtNumAnticipo.getText());
            String banco= this.txtBanco.getText();
            double montoAnticipo= Double.parseDouble(this.txtMontoAnticipo.getText());
            String objetivo= this.TxtObjetivo.getText();
            String Observaciones= this.txtObservaciones.getText();
            String []separarJefe= this.cmbAutoriza.getSelectedItem().toString().split("-");
            int autoriza= Integer.parseInt(separarJefe[1]);
            String fechaReintegro=this.txtDia.getText()+"/"+this.txtMes.getText()+"/"+this.txtAño1.getText();
            double Total = Double.valueOf(LblTotalViaticos.getText());
            double Resultado = Double.parseDouble(LblResultado.getText());
            int IDRecibo = Integer.parseInt(txtIDRecibo.getText());
            OrdenDeViaticos OrdenViatico = new OrdenDeViaticos(numOrden, numeroAnticpio, banco, fecha, montoAnticipo, objetivo, Observaciones, cedula, autoriza, 0, "Pendiente Aprobacion", Total, Resultado, fechaReintegro, IDRecibo);

            try {
                BLOrden.insertarOrdenDeViaticos(OrdenViatico);

                //GuardarRegistrodeViaticos
                BLViaticoPorDia.AgregarListaViaticos(TblViaticosDia.getModel());
                //GuardarOtrosGasto
                BLGastoAdicional.AgregarListaGastos(TblOtrosGastos.getModel());
            } catch (SQLException ex) {
                Logger.getLogger(FrmOrdenDeViaticos.class.getName()).log(Level.SEVERE, null, ex);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(FrmOrdenDeViaticos.class.getName()).log(Level.SEVERE, null, ex);
            } catch (ParseException ex) {
                Logger.getLogger(FrmOrdenDeViaticos.class.getName()).log(Level.SEVERE, null, ex);
            }
            JOptionPane.showMessageDialog(rootPane, "Viatico Registrado correctamente");
                this.setVisible(false);
        }else
        {
            JOptionPane.showMessageDialog(rootPane,"No se ha calculado los gastos");
        }
    }//GEN-LAST:event_btnAgregarActionPerformed

    private void BtnAgregarDesgloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnAgregarDesgloseActionPerformed
        // TODO add your handling code here:
        VentanaDiaViatico = new FrmDiaViatico(numOrden);
        VentanaDiaViatico.setTabla(TblViaticosDia);
        VentanaDiaViatico.setVisible(true);
        
    }//GEN-LAST:event_BtnAgregarDesgloseActionPerformed



    private void txtIDReciboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtIDReciboActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtIDReciboActionPerformed

    private void BtnAgregarOtroDetalleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnAgregarOtroDetalleActionPerformed
        // TODO add your handling code here:
        VentanaOtrosGastos = new  FrmOtrosGastos(numOrden);
        VentanaOtrosGastos.setTabla(TblOtrosGastos);
        VentanaOtrosGastos.setVisible(true);
    }//GEN-LAST:event_BtnAgregarOtroDetalleActionPerformed

    private void BtnCalcularGastosDiariosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnCalcularGastosDiariosActionPerformed
        // TODO add your handling code here:
        bandera=true;
        Utilitarios.CalcularMontos(ModeloTablaViaticos);
        LblTotalHospedaje.setText(""+Utilitarios.getHospedaje());
        LblTotalAlimentacion.setText(""+Utilitarios.getAlimentacion());
        LblSubTotal1.setText(""+Utilitarios.getSubtotal());
        Utilitarios.CalcularOtrosGastos(ModeloOtrosGastos);
        LblTotalOtros.setText(""+Utilitarios.getSubTotalOTros());
        LblTotalViaticos.setText(""+Utilitarios.getSumaSubTotal());
        LblResultado.setText(""+Utilitarios.getResta(txtMontoAnticipo.getText()));
    }//GEN-LAST:event_BtnCalcularGastosDiariosActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void txtAño1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtAño1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtAño1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrmOrdenDeViaticos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrmOrdenDeViaticos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrmOrdenDeViaticos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrmOrdenDeViaticos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BtnAgregarDesglose;
    private javax.swing.JButton BtnAgregarOtroDetalle;
    private javax.swing.JButton BtnCalcularGastosDiarios;
    private javax.swing.JLabel LblAnticipo;
    private javax.swing.JLabel LblAutoriza;
    private javax.swing.JLabel LblBanco;
    private javax.swing.JLabel LblCedula;
    private javax.swing.JLabel LblDD;
    private javax.swing.JLabel LblFechaReintegro;
    private javax.swing.JLabel LblFechaReintegro1;
    private javax.swing.JLabel LblMM;
    private javax.swing.JLabel LblMonto;
    private javax.swing.JLabel LblObjetivo;
    private javax.swing.JLabel LblObservaciones;
    private javax.swing.JLabel LblOtrosGastos;
    private javax.swing.JLabel LblResta;
    private javax.swing.JLabel LblResultado;
    private javax.swing.JLabel LblSubTotal1;
    private javax.swing.JLabel LblSubTotal1L;
    private javax.swing.JLabel LblTitulo;
    private javax.swing.JLabel LblTotal;
    private javax.swing.JLabel LblTotalAlimen;
    private javax.swing.JLabel LblTotalAlimentacion;
    private javax.swing.JLabel LblTotalHospedaje;
    private javax.swing.JLabel LblTotalHospedajeL;
    private javax.swing.JLabel LblTotalOtros;
    private javax.swing.JLabel LblTotalOtrosL;
    private javax.swing.JLabel LblTotalViaticos;
    private javax.swing.JLabel LblYYYY;
    private javax.swing.JTable TblOtrosGastos;
    private javax.swing.JTable TblViaticosDia;
    private javax.swing.JTextField TxtObjetivo;
    private javax.swing.JButton btnAgregar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JComboBox cmbAutoriza;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JTable jTable1;
    private javax.swing.JLabel lbFecha;
    private javax.swing.JLabel lbNum;
    private javax.swing.JTextField txtAño1;
    private javax.swing.JTextField txtBanco;
    private javax.swing.JTextField txtCedula;
    private javax.swing.JTextField txtDia;
    private javax.swing.JTextField txtIDRecibo;
    private javax.swing.JTextField txtMes;
    private javax.swing.JTextField txtMontoAnticipo;
    private javax.swing.JTextField txtNumAnticipo;
    private javax.swing.JTextField txtObservaciones;
    // End of variables declaration//GEN-END:variables
}
